#include <stdio.h>
#include <stdlib.h>

//https://www.nowcoder.com/practice/2f058b1e89ae43f7ab650c0fd0b71fa8?tpId=290&tqId=618634&ru=/exam/oj/ta&qru=/ta/beginner-programmers/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D290

typedef struct ARR {
    int N;
    int Arr[0];
}ARR;

int main() {
    int count = 0;
    int row = 0;
    int col = 0;
    scanf("%d%d", &row, &col);
    ARR *arr1 = (ARR *) malloc(sizeof(ARR) + row * col * sizeof(int));
    if (arr1) {
        perror("堆区开辟空间失败:");
    }
    arr1->N = row * col;
    ARR *arr2 = (ARR *) malloc(sizeof(ARR) + row * col * sizeof(int));
    if (arr2) {
        perror("堆区开辟空间失败:");
    }
    arr2->N = row * col;
    for (int i = 0; i < arr1->N; i++) {
        scanf("%d", arr1->Arr + i);
    }
    for (int i = 0; i < arr2->N; i++) {
        scanf("%d", arr2->Arr + i);
    }
    for (int i = 0; i < arr1->N; i++) {
        if (arr1->Arr[i] == arr2->Arr[i]) {
            count++;
        }
    }
    if (count == row * col) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}